home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / coreaids.zip / GET_TEXT.ASM < prev    next >
Assembly Source File  |  1987-06-25  |  1KB  |  60 lines

  1. ;    DESC:    gets a line of text from the keyboard                V1.00
  2. ;    IN:    *{MAX_CHARS} maximum # of characters to get from keyboard
  3. ;    OUT:    *{SEG_VAL} segment and
  4. ;        *{OFFSET} offset of text buffer
  5. ;        *{LENGTH} length of text
  6. ;    SAMPLE:    Callm    GET_CHAR,<MAX_CHARS>,<SEG_VAL,OFFSET,LENGTH>
  7. ;    ##################################################################
  8.  
  9. GET_TEXD Segment Para Public 'DATA'
  10. BUFFER        DB    80H DUP(20H)        ;input buffer.
  11. GET_TEXD Ends
  12.  
  13.  
  14.     Extrn    PUSHALL:Near
  15.     Extrn    POPALL:Near
  16.  
  17. GET_TEXC    Segment
  18.     Assume    CS:GET_TEXC
  19.     Public    GET_TEXT
  20.                         ;notice.
  21.     DB    'GET_TEXT - V1.00, Copyright 1987, CoreTechs   ',0DH,0AH
  22.  
  23. GET_TEXT    Proc    Near            ;get character from keyboard.
  24.  
  25.     Call    PUSHALL                ;save registers.
  26.  
  27.     Mov    AX,GET_TEXD            ;setup workarea.
  28.     Mov    DS,AX
  29.  
  30.     Mov    BP,OFFSET BUFFER        ;locate buffer.
  31.  
  32.     Pop    CX                ;get max. # of chars to get.
  33.  
  34. ANOTHR:    Mov    AH,0                ;get a char from keyboard.
  35.     Int    16H
  36.  
  37.     Mov    DS:[BP],AX            ;store character in buffer.
  38.     Inc    BP
  39.  
  40.     Cmp    AX,1C0DH            ;see if end of line?
  41.     Jz    FINITO
  42.  
  43.     Cmp    BP,CX                ;see if max chars is exceeded.
  44.     Jz    FINITO
  45.  
  46.     Jmp    ANOTHR                ;else, get next char.
  47.  
  48. FINITO:    Push    BP                ;return buffer length.
  49.  
  50.     Mov    AX,OFFSET BUFFER        ;return buffer address.
  51.     Push    AX
  52.     Push    DS
  53.  
  54.     Call    POPALL                ;restore registers
  55.     Ret
  56.  
  57. GET_TEXT    Endp
  58. GET_TEXC    Ends
  59.     End
  60.